package com.tlgen.utils;

import java.io.*;

/**
 * 文件工具类
 */
public class FileUtils {

    /**
     * 创建文件并写入内容
     */
    public static void createFile(String content) {
        try {
            File file = new File("C:\\Users\\tlgen\\cooperos\\app-local-config.yml");
            // 清空文件内容,  new FileWriter(file) 即使没有文件也会创建一个虚拟的文件
            FileWriter fileWriter = new FileWriter(file);
            fileWriter.write("");
            fileWriter.flush();
            fileWriter.close();
            // 写入内容
            BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8"));
            w.write(content);
            w.flush();
            w.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
